/*
 *  Author: Sinclair Ross
 *  Date: 29/04/2014
 *  Description: 
 *
 *
 *
 */

package com.forbiddendesert.master;

import com.forbiddendesert.logic.GameLogic;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity
{
	public static int REQUEST_RENDER = 1; 
	public int height;
	public int width;
	GameView mGameView;
	GameThread mGameThread;
	GameLogic mGameLogic;
	RendererPacket mRendererPacket;
	Handler mHandler;
	
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
       
        DisplayMetrics displaymetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
		height = displaymetrics.heightPixels;
		width = displaymetrics.widthPixels;
		
        mHandler = new Handler(Looper.getMainLooper()) 
        { 
            @Override
            public void handleMessage(Message msg) 
            { 
                super.handleMessage(msg); 
                  
                switch(msg.what) 
                { 
                case 1: 
                    mHandler.removeMessages(REQUEST_RENDER); 
                    break;   
                } 
            } 
        }; 
        
        mRendererPacket = new RendererPacket();
        mGameLogic = new GameLogic(mRendererPacket, this);
        
        mGameThread = new GameThread(this, mHandler, mRendererPacket, mGameLogic); 
        mGameThread.start();   
        
        mGameView = new GameView(this, mHandler, mRendererPacket, mGameLogic); 
        setContentView(mGameView);          
    }

}
